package cn.nohan.funplay.module.member.mongo.controller;

import cn.nohan.funplay.module.member.mongo.entity.MongoUserTrajectoryEntity;
import cn.nohan.funplay.module.member.mongo.service.LocationService;
import cn.nohan.funplay.module.member.mongo.service.UserTrajectoryService;
import com.mongoplus.model.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author caozhipeng
 * @date 2025/8/1
 */
@RestController
@RequestMapping("/location")
public class LocationController {

    @Autowired
    private LocationService locationService;

    @Autowired
    private UserTrajectoryService userTrajectoryService;

    @RequestMapping("/performGeoQueries1")
    public  List<MongoUserTrajectoryEntity> performGeoQueries1(){
        return locationService.performGeoQueries1();
    }

    @RequestMapping("/performGeoQueriesPage2")
    public Page<MongoUserTrajectoryEntity> performGeoQueries2(@RequestParam("pageNum") int pageNum,
                                                             @RequestParam("pageSize") int pageSize,
                                                             @RequestParam("maxDistance") double maxDistance){
        return locationService.performGeoQueries2(pageNum, pageSize,maxDistance);
    }
    @RequestMapping("/performGeoQueries3")
    public  List<MongoUserTrajectoryEntity> performGeoQueries3(@RequestParam("maxDistance") double maxDistance){
        return locationService.performGeoQueries3(maxDistance);
    }

    @RequestMapping("/findNearbyLocations")
    public  Page<MongoUserTrajectoryEntity> findNearbyLocations(@RequestParam("pageNum") int pageNum,
                                                                @RequestParam("pageSize") int pageSize){
        return locationService.findNearbyLocations(pageNum,pageSize);
    }

    @RequestMapping("/performGeoQueriesPage4")
    public Page<MongoUserTrajectoryEntity> performGeoQueries4(@RequestParam("pageNum") int pageNum,
                                                              @RequestParam("pageSize") int pageSize,
                                                              @RequestParam("maxDistance") double maxDistance){
        return locationService.performGeoQueries4(pageNum-1, pageSize,maxDistance);
    }

    @RequestMapping("/init")
    public  void init(){
         locationService.init();
    }

    @RequestMapping("/findNearbyUsers")
    public List<MongoUserTrajectoryEntity> findNearbyUsers(@RequestParam("maxDistance") double maxDistance,
                                                                 @RequestParam("minDistance") double minDistance) {
        return userTrajectoryService.findNearbyUsers(maxDistance, minDistance);
    }

}
